home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / csim / source.lha / source / C++SIM / Random.h < prev    next >
C/C++ Source or Header  |  1993-06-14  |  4KB  |  129 lines

  1. /*
  2.  * Copyright (C) 1993
  3.  *
  4.  * Department of Computing Science,
  5.  * The University,
  6.  * Newcastle upon Tyne,
  7.  * UK.
  8.  */
  9.  
  10. #ifndef RANDOM_H_
  11. #define RANDOM_H_
  12.  
  13. #ifndef COMMON_H_
  14. #include "common.h"
  15. #endif
  16.  
  17.  
  18. ////////////////////////////////////////////////////////////////////////////////
  19. //                                                                            //
  20. //  This file contains the interfaces for five different (pseudo-) random     //
  21. //  number  generators:                                                       //
  22. //                                                                            //
  23. //  1) Uniform -          returns a  number drawn from a uniform distribution //
  24. //                        with the given lower and upper bounds.              //
  25. //                        Note: there are two versions of this class, one     //
  26. //                              returning integers and the other doubles      //
  27. //                                                                            //
  28. //  2) Exponential -      returns a number from an exponential distribution   //
  29. //                        with the given mean                                 //
  30. //                                                                            //
  31. //  3) Erlang -           returns a number from an Erlang distribution with   //
  32. //                        the given mean and standard deviation               //
  33. //                                                                            //
  34. //  4) HyperExponential - returns a number from a hyperexpontial distribution //
  35. //                        with the given mean and standard deviation          //
  36. //                                                                            //
  37. //  5) Normal -           returns a number from a normal distribution with    //
  38. //                        the given mean and standard deviation.              //
  39. //                                                                            //
  40. ////////////////////////////////////////////////////////////////////////////////
  41.  
  42.  
  43. ////////////////////////////////////////////////////////////////////////////////
  44. // The class RandomStream is an abstract base class from which the other      //
  45. // distribution classes are derived.                                          //
  46. ////////////////////////////////////////////////////////////////////////////////
  47. class RandomStream
  48. {
  49. public:
  50.     RandomStream (long MGSeed=772531L, long LCGSeed=1878892440L);
  51.     virtual double operator() ()=0;
  52.     double Error ();    // returns a chi-square error measure on the uniform
  53.             // distribution function
  54. protected:
  55.     double Uniform ();
  56.  
  57. private:
  58.     double MGen ();
  59.     double series[128];
  60.     long MSeed, LSeed;
  61. };
  62.  
  63. class UniformStream : public RandomStream
  64. {
  65. public:
  66.     UniformStream (double lo, double hi, int StreamSelect=0);
  67.     virtual double operator() ();
  68.  
  69. private:
  70.     double lo,hi;
  71.     double range;
  72. };
  73.  
  74. class Draw
  75. {
  76. public:
  77.     Draw (double p, int StreamSelect=0);
  78.     virtual boolean operator() ();
  79. private:
  80.     UniformStream s;
  81.     double prob;
  82. };
  83.  
  84. class ExponentialStream : public RandomStream
  85. {
  86. public:
  87.     ExponentialStream (double Mean, int StreamSelect=0);
  88.     virtual double operator() ();
  89.  
  90. private:
  91.     double Mean;
  92. };
  93.  
  94. class ErlangStream : public RandomStream
  95. {
  96. public:
  97.     ErlangStream (double Mean, double StandardDeviation, int StreamSelect=0);
  98.     virtual double operator() ();
  99.  
  100. private:
  101.     double Mean,StandardDeviation;
  102.     long k;
  103. };
  104.  
  105. class HyperExponentialStream : public RandomStream
  106. {
  107. public:
  108.     HyperExponentialStream (double Mean, double StandardDeviation, int StreamSelect=0);
  109.     virtual double operator() ();
  110.  
  111. private:
  112.     double Mean,StandardDeviation;
  113.     double p;
  114. };
  115.  
  116. class NormalStream : public RandomStream
  117. {
  118. public:
  119.     NormalStream (double Mean, double StandardDeviation, int StreamSelect=0);
  120.     virtual double operator() ();
  121.  
  122. private:
  123.     double Mean,StandardDeviation;
  124.     double z;
  125. };
  126.  
  127. #endif // RANDOM_H
  128.  
  129.